package com.techsoul.module.pms.controller;

import com.techsoul.common.core.pojo.Result;
import com.techsoul.common.log.annotation.Log;
import com.techsoul.common.log.enums.OperationTypeEnum;
import com.techsoul.module.pms.pojo.param.TWmsDeliveryPickupPlanSaveParam;
import com.techsoul.module.pms.pojo.param.TWmsReciptIntoLocPlanSaveParam;
import com.techsoul.module.pms.pojo.param.TWmsReciptIntoLocPlanSearchParam;
import com.techsoul.module.pms.service.ITWmsReciptIntoLocPlanService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.Arrays;

/**
 * 上架计划 Controller
 *
 * @author liuen
 * @date 2023-03-28
 */
@Api(tags = "上架计划")
@RestController
@RequestMapping("/web/tWmsReciptIntoLocPlan")
public class TWmsReciptIntoLocPlanController {

    @Autowired
    private Result result;
    
    @Autowired
    private ITWmsReciptIntoLocPlanService service;

    @ApiOperation("新增")
    @Log(title = "上架计划", operationType = OperationTypeEnum.INSERT)
    @PreAuthorize("hasAnyAuthority('web:tWmsReciptIntoLocPlan:insert')")
    @PostMapping
    public Result insert(@Valid @RequestBody TWmsReciptIntoLocPlanSaveParam params) {
        return result.success(this.service.insert(params));
    }

    @ApiOperation("批量删除（多个用逗号隔开）")
    @Log(title = "上架计划", operationType = OperationTypeEnum.DELETE)
    @PreAuthorize("hasAnyAuthority('web:tWmsReciptIntoLocPlan:delete')")
    @DeleteMapping("/{ids}")
    public Result batchDelete(@PathVariable String[] ids) {
        return result.success(this.service.batchDelete(Arrays.asList(ids)));
    }

    @ApiOperation("修改")
    @Log(title = "上架计划", operationType = OperationTypeEnum.UPDATE)
    @PreAuthorize("hasAnyAuthority('web:tWmsReciptIntoLocPlan:update')")
    @PutMapping
    public Result update(@Valid @RequestBody TWmsReciptIntoLocPlanSaveParam params) {
        return result.success(this.service.update(params));
    }

    @ApiOperation("详情")
    @PreAuthorize("hasAnyAuthority('web:tWmsReciptIntoLocPlan:search')")
    @GetMapping("/{id}")
    public Result findById(@PathVariable("id") String id) {
        return result.success(this.service.findById(id));
    }

    @ApiOperation("列表")
    @PreAuthorize("hasAnyAuthority('web:tWmsReciptIntoLocPlan:search')")
    @PostMapping("/search")
    public Result findAll(@RequestBody TWmsReciptIntoLocPlanSearchParam params) {
        return result.success(this.service.findAll(params));
    }
    @ApiOperation("上架计划")
    @Log(title = "上架计划", operationType = OperationTypeEnum.GENINLOC)
    @PreAuthorize("hasAnyAuthority('web:tWmsDeliveryPickupPlan:genPickupPlan')")
    @PostMapping("/genInLocPlan")
    public Result genInLocPlan() {
        return result.success(this.service.genInLocPlan());
    }


    @ApiOperation("上架计划发布")
    @Log(title = "上架计划发布", operationType = OperationTypeEnum.GENINLOC)
   // @PreAuthorize("hasAnyAuthority('web:tWmsReciptIntoLocPlan:publish')")
    @PostMapping("/handlePublish")
    public Result handlePublish() {
        return result.success(this.service.handlePublish());
    }

    @ApiOperation("手动上架计划明细")
    @Log(title = "手动上架计划明细", operationType = OperationTypeEnum.GENINLOC)
    @PreAuthorize("hasAnyAuthority('web:tWmsDeliveryPickupPlan:genPickupPlan')")
    @PostMapping("/genInLocPlanBySelectItem/{ids}")
    public Result genInLocPlanBySelectItem(@RequestBody TWmsReciptIntoLocPlanSaveParam params,@PathVariable String[] ids) {

        return result.success(this.service.genInLocPlanBySelectItem(params,ids));
    }

    @ApiOperation("抢单")
    @Log(title = "抢单", operationType = OperationTypeEnum.getJob)
    @PreAuthorize("hasAnyAuthority('web:tWmsReciptIntoLocPlan:getJob')")
    @GetMapping("/getInlocJob/{id}")
    public Result getInlocJob( @PathVariable String id) {
        return result.success(this.service.getInLocJob(id));
    }


    @ApiOperation("手动上架计划")
    @Log(title = "上架计划", operationType = OperationTypeEnum.GENINLOC)
    @PreAuthorize("hasAnyAuthority('web:tWmsReciptIntoLocPlan:genInLocPlanBySelect')")
    @PostMapping("/genInLocPlanBySelect/{ids}")
    public Result genInLocPlanBySelect(@RequestBody TWmsReciptIntoLocPlanSaveParam params,@PathVariable String[] ids) {

        return result.success(this.service.genInLocPlanBySelect(params,ids));
    }
    @ApiOperation("上架操作") //操作员具体操作时手持调用
    @Log(title = "上架操作", operationType = OperationTypeEnum.INLOC)
    @PreAuthorize("hasAnyAuthority('web:tWmsReciptIntoLocPlan:putInLoc')")
    @PostMapping("/putInLoc/{ids}")
    public Result putInLoc(@RequestBody TWmsReciptIntoLocPlanSaveParam params,@PathVariable String[] ids) {
        return result.success(this.service.putInLoc(params.getLocationNo(),params.getContianBoxNo(),params.getLotNo(),ids));
    }
    @ApiOperation("列表-分页")
    @PreAuthorize("hasAnyAuthority('web:tWmsReciptIntoLocPlan:search')")
    @PostMapping("/search/{current}/{pageSize}")
    public Result findAll(@RequestBody TWmsReciptIntoLocPlanSearchParam params, @PathVariable Integer current, @PathVariable Integer pageSize) {
        return result.success(this.service.findAll(params, current, pageSize));
    }

}
